package com.pirestupppai.ui.fragment;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseFragment;
import com.pirestupppai.rxbus.RxBus;

import butterknife.BindView;
import rx.Subscription;
import rx.functions.Action1;

import static com.pirestupppai.rxbus.RxBus.RXBUS_REFRESH_USER_DESC;

/**
 * author: xiaoluo
 * date: 2017/6/23 10:11
 */
public class UserDescFragment extends BaseFragment {

    @BindView(R.id.user_desc_tv)
    TextView descTv;

    private Subscription mSubscription;

    @Override
    protected Context getFragmentContext() {
        return getActivity();
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.fragment_user_desc;
    }

    @Override
    protected void initViews() {
        //注册观察者
        mSubscription = RxBus.getInstance()
                .toObservable(RXBUS_REFRESH_USER_DESC, String.class)
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        if (TextUtils.isEmpty(s)) {
                            descTv.setText("这个家伙很懒,什么也没有留下");
                        } else {
                            descTv.setText(s);
                        }
                    }
                });
    }

    @Override
    protected void initListeners() {

    }

    @Override
    protected void initLogic() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (!mSubscription.isUnsubscribed()) {
            mSubscription.unsubscribe();
        }
    }


}
